package com.cssw.fyzb.core.dao.system;

import com.cssw.fyzb.core.model.dodb.AppVersion;
import org.springframework.stereotype.Repository;

/**
 * @Author zhouxu
 * @create 2020-08-25 17:31
 */
@Repository
public class AppVersionDaoImpl implements AppVersionDao {
    @Override
    public AppVersion getVersion(String appName, String type) {
        String sql = "select * from t_app_version where  app_name = ? and type = ? ";

        return AppVersion.dao.findFirst(sql, appName, type);
    }

    @Override
    public void updateVersionOFF(String appName, String type) {
        AppVersion version = getVersion(appName, type);
        if (version != null) {
            version.setActive(AppVersion.ACTIVE_OFF);
            version.update();

        }
    }

    @Override
    public void updateAppVersion(
            String name, String appName, String appUrl1, String appUrl2,
            String versionName, String versionCode, String content, String type, String forceUpdate
    ) {
        AppVersion newVersion = new AppVersion();
        newVersion.setName(name);
        newVersion.setAppName(appName);
        newVersion.setAppUrl1(appUrl1);
        newVersion.setAppUrl2(appUrl2);
        newVersion.setVersionName(versionName);
        newVersion.setVersionCode(versionCode);
        newVersion.setActive(AppVersion.ACTIVE_ON);
        newVersion.setContent(content);
        newVersion.setType(type);
        newVersion.setForceUpdate(forceUpdate);
        newVersion.save();

    }

}
